file(GLOB_RECURSE CUDA_OPS_SRC_LIST RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "*.cu")
if(NOT MSVC)
    if(${CUDA_VERSION} VERSION_GREATER 11.3)
        set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unknown-pragmas")
    endif()
endif()

if(CMAKE_SYSTEM_NAME MATCHES "Darwin")
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-delete-non-abstract-non-virtual-dtor -Wno-overloaded-virtual")
endif()

if(${CUDA_VERSION} VERSION_LESS 11.0)
    if(NOT MSVC)
        string(REPLACE "-std=c++17" "-std=c++11" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
    endif()
else()
    if(NOT MSVC)
        string(REPLACE "-std=c++17" "-std=c++14" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
        set(CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS} -std=c++14 -objtemp")
    endif()
endif()

set_property(SOURCE ${CUDA_OPS_SRC_LIST} PROPERTY COMPILE_DEFINITIONS SUBMODULE_ID=mindspore::SubModuleId::SM_KERNEL)
if(MSVC)
    add_compile_definitions(BUILDING_CUDA_OPS_DLL)
    set(CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS} -DBUILDING_CUDA_OPS_DLL -std=c++17")
    set(CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS} -D_DISABLE_EXTENDED_ALIGNED_STORAGE")
endif()
if(ENABLE_GPU)
    add_library(cuda_common_obj OBJECT cuda_ops/cuda_common.cc  cuda_ops/cuda_device_info.cc)
    if(NOT MSVC)
    target_compile_options(cuda_common_obj PRIVATE "-std=c++17")
    else()
    target_compile_options(cuda_common_obj PRIVATE "/std:c++17")
    endif()
    cuda_add_library(cuda_ops SHARED ${CUDA_OPS_SRC_LIST} $<TARGET_OBJECTS:cuda_common_obj>)
    if(NOT BUILD_LITE)
      set_target_properties(cuda_ops PROPERTIES SOVERSION ${CUDA_VERSION_MAJOR})
    endif()
    if(NOT MSVC)
        target_link_options(cuda_ops PRIVATE "-Wl,--allow-shlib-undefined")
    else()
        target_link_options(cuda_ops PRIVATE "/FORCE:UNRESOLVED")
        target_link_libraries(cuda_ops mindspore_core)
    endif()
endif()